package com.IntelligenceInsight.Myth.mapper;

import com.IntelligenceInsight.Myth.model.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
@Repository
public interface UserMapper {
    @Select("SELECT * FROM user WHERE username = #{username} AND password = #{password}")
    User Login(@Param("username") String username, @Param("password") String password);

    @Select("SELECT COUNT(#{username}) FROM user")
    int UserCountByUserName(@Param("username") String username);

    @Select("SELECT * FROM user")
    List<User> UserListAll();

    @Select("SELECT * FROM user WHERE userType=#{userType}")
    List<User> UserListByUserType(@Param("userType") int userType);

    @Insert("INSERT INTO user(username, password, userType, email, realName) " +
            "VALUES(#{username}, #{password}, #{userType}, #{email}, #{realName})")
    int UserAdd(@Param("username") String username, @Param("password") String password, @Param("userType") int userType, @Param("email") String email, @Param("realName")  String realName);

    @Update("UPDATE user SET password=#{password} WHERE username=#{username}")
    int UserPasswordChange(@Param("password") String password, @Param("username") String username);

    @Update("UPDATE user SET email=#{email}, realName=#{realName} WHERE username=#{username}")
    int UserInfoChange(@Param("email") String email, @Param("realName") String realName, @Param("username") String username);

    @Delete("DELETE FROM user WHERE username=#{username}")
    int UserRemove(@Param("username") String username);
}
